package com.yjj.springboot3.model.json;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
import java.util.List;

/**
 * 聊天消息列表包装类
 */
public class ChatMessageList {
    
    /**
     * 消息列表
     */
    @JsonProperty("messages")
    private List<ChatMessage> messages;
    
    /**
     * 总消息数量
     */
    @JsonProperty("totalCount")
    private int totalCount;
    
    /**
     * 创建时间戳
     */
    @JsonProperty("timestamp")
    private long timestamp;
    
    public ChatMessageList() {
        this.messages = new ArrayList<>();
        this.timestamp = System.currentTimeMillis();
    }
    
    public ChatMessageList(List<ChatMessage> messages) {
        this.messages = messages != null ? messages : new ArrayList<>();
        this.totalCount = this.messages.size();
        this.timestamp = System.currentTimeMillis();
    }
    
    public List<ChatMessage> getMessages() {
        return messages;
    }
    
    public void setMessages(List<ChatMessage> messages) {
        this.messages = messages != null ? messages : new ArrayList<>();
        this.totalCount = this.messages.size();
    }
    
    public int getTotalCount() {
        return totalCount;
    }
    
    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }
    
    public long getTimestamp() {
        return timestamp;
    }
    
    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }
    
    /**
     * 添加单个消息
     */
    public void addMessage(ChatMessage message) {
        if (message != null) {
            this.messages.add(message);
            this.totalCount = this.messages.size();
        }
    }
    
    /**
     * 添加多个消息
     */
    public void addMessages(List<ChatMessage> messages) {
        if (messages != null && !messages.isEmpty()) {
            this.messages.addAll(messages);
            this.totalCount = this.messages.size();
        }
    }
    
    /**
     * 清空消息
     */
    public void clear() {
        this.messages.clear();
        this.totalCount = 0;
    }
    
    @Override
    public String toString() {
        return "ChatMessageList{" +
                "totalCount=" + totalCount +
                ", timestamp=" + timestamp +
                ", messages=" + messages +
                '}';
    }
}
